﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using ParserGenerator.SyntacticAnalysis;

namespace ParserGenerator.ScannerConstruction
{
    [Serializable]
    public sealed class ScannerAutomatonReductionsTable : ReadOnlyDictionary<LexicalRuleDeclarator, int>
    {
        internal ScannerAutomatonReductionsTable(ScannerAutomatonStateTable states)
            : base(new Dictionary<LexicalRuleDeclarator, int>())
        {
            if (states == null)
                throw new ArgumentNullException(nameof(states));
            foreach (ScannerAutomatonState state in states)
                foreach (LexicalRuleDeclarator rule in state.Reductions)
                    if (!Dictionary.ContainsKey(rule))
                        Dictionary.Add(rule, Dictionary.Count);
        }
    }
}
